// pages/homelink/zhaoqiye/zhaoqiye.js
import Dialog from "../../../../miniprogram_npm/@vant/weapp/dialog/dialog";

Page({
  /**
   * 页面的初始数据
   */
  data: {
    longitude: "",
    latitude: "",
    distance: "1.0",
    pageNum: 1,
    currentPos: "",
    prolist: [],
    serach_pro: "",
    prosum: 0,
  },
  // 搜索
  // serachProChange(e) {
  //   this.setData({
  //     serach_pro: e.detail,
  //   });
  //   if (e.detail && e.detail.length > 3) {
  //     var setinval = null;
  //     if (setinval) {
  //       clearTimeout(setinval);
  //       setinval = null;
  //     } else {
  //       setinval = setTimeout(() => {
  //         this.getList();
  //       }, 1000);
  //     }
  //   } else if (e.detail) {
  //     // this.setData({
  //     //   serach_pro: "",
  //     //   prolist: []
  //     // })
  //     // Toast("！")
  //   } else {
  //     this.setData({
  //       serach_pro: "",
  //       prolist: [],
  //     });
  //   }
  // },
  serachProChange (e) {
    this.setData({
      serach_pro: e.detail,
    });
  },
  firstSearch () {
    this.setData({
      prolist: [],
      prosum: ''
    });
    this.getList()
  },
  goSearch () {
    this.firstSearch()
  },
  todizhi () {
    var that = this;
    wx.chooseLocation({
      success (res) {
        that.setData({
          // zb: JSON.stringify({
          //   longitude: res.longitude,
          //   latitude: res.latitude,
          // }),
        });
        console.log(res, "返回的结果");
        // 重新定位中心点
        // that.initInfoByCenter(res);
        // that.initInfoByCenter({ longitude: 120.642391, latitude: 31.369189 });
        console.log(res, "成功回调");
      },
      fail (res) {
        console.log(res, "失败回调");
      },
      complete (res) {
        console.log(res, "结束回调");
      },
    });
  },
  toshoudai () {
    // Toast("当前功能暂未开放，敬请期待！");
    Dialog.confirm({
      title: "",
      message: "请先登录！",
    })
      .then(() => {
        wx.navigateTo({
          url: "/pages/login/login",
        });
      })
      .catch(() => {
        // on cancel
        wx.switchTab({
          url: "/pages/shouye/shouye",
        });
      });
    // wx.navigateTo({
    //   url: '/packageA/pages/homelink/zqy_shoudai/zqy_shoudai'
    // })
  },
  getList () {
    this.setData({
      prolist: [],
      pageNum: 1,
    });
    var _this = this;
    wx.showLoading({
      title: "加载中",
    });
    const params = {
      pageBO: {
        pageSize: 50,
        pageNum: 1,
      },
      searchParam: _this.data.serach_pro,
    };
    // var condtion = Object.assign(params, this.data.allConditions)
    // console.log(condtion);
    getApp()
      .globalData.request("/map/fullAmountCorp", params, "POST")
      .then((res) => {
        setTimeout(function () {
          wx.hideLoading();
        }, 500);
        var rstObj = res;
        console.log(res);
        _this.setData({
          prolist: rstObj.data.list,
          prosum: rstObj.data.total,
        });
      });
  },
  getlistgengduo () {
    var _this = this;
    wx.showLoading({
      title: "加载中",
    });
    const params = {
      pageBO: {
        pageSize: 50,
        pageNum: this.data.pageNum,
      },
      searchParam: _this.data.serach_pro,
    };
    // var condtion = Object.assign(params, this.data.allConditions)
    // console.log(condtion);
    getApp()
      .globalData.request("/map/fullAmountCorp", params, "POST")
      .then((res) => {
        setTimeout(function () {
          wx.hideLoading();
        }, 500);
        var rstObj = res;
        console.log(res);
        _this.setData({
          prolist: _this.data.prolist.concat(rstObj.data.list),
          prosum: rstObj.data.total,
        });
      });
  },
  // 滑动底部加载更多
  scrollBottom () {
    this.onBottom();
  },
  onBottom () {
    this.data.pageNum++;
    this.getlistgengduo();
  },

  toprodetail (e) {
    // console.log(e.detail, 'e.detail')
    wx.navigateTo({
      url: `/packageA/pages/homelink/tonghangyepk/tonghangyepk?corpKey=${e.detail.corpKey}&d2CorpName=${e.detail.d2CorpName}&hangye=${e.detail.d2Industryco}`,
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad (options) {
    this.setData({
      serach_pro: options.searchvalue
    })
    if (this.data.serach_pro) {
      this.firstSearch()
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady () { },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow () { },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide () { },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload () { },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh () { },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom () { },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage () { },
});